import 'package:byw_blog/model/SearchHistoryModel.dart';
import 'package:byw_blog/database/DatabaseHelp.dart';
import 'package:byw_blog/utils/ParameterUtil.dart';

class SearchHistoryTable {

  /// 查找最近十条的搜索数据
  static Future<List<Map<String, Object?>>> queryLast10() {
    return DatabaseHelp.getDatabase().query(ParameterUtil.TABLE_SEARCH_HISTORY,
        orderBy: ' id desc ', limit: 10);
  }

  /// 插入一条新的搜索历史
  static Future<int> insert(SearchHistoryModel bean) {
    return DatabaseHelp.getDatabase()
        .insert(ParameterUtil.TABLE_SEARCH_HISTORY, bean.toMap(bean));
  }

  /// 删除搜索历史
  static Future<int> delete(String value) {
    return DatabaseHelp.getDatabase().delete(ParameterUtil.TABLE_SEARCH_HISTORY,
        where: "value = ?", whereArgs: [value]);
  }

  /// 判断某一个数据是否存在
  static Future<List<Map<String, Object?>>> isExist(String value) {
    return DatabaseHelp.getDatabase().query(ParameterUtil.TABLE_SEARCH_HISTORY,
        where: "value = ?", whereArgs: [value]);
  }
}
